package cn.yunhe.server;

import cn.yunhe.dao.IQuestionDao;
import cn.yunhe.entity.Question;
import cn.yunhe.entity.Test;
import cn.yunhe.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class QuestionServer {
    SqlSession session = SqlSessionFactoryUtil.getSqlSession();
    IQuestionDao questionDao = session.getMapper(IQuestionDao.class);

    /**
     * 插入问题
     * @param context
     * @param tId
     * @return
     */
    public boolean InsertQuestion(String context,int tId){
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("context",context);
        map.put("tId",tId);
        boolean flag = questionDao.InsertQuestion(map);
        if (flag){
            session.commit();
            return true;
        }else {
            return false;
        }

    }

    /**
     * 通过题目名称查询试题对象
     * @param context
     * @return
     */
    public Question AccureSelectQuestion(String context){
        return questionDao.AccureSelectQuestion(context);
    }

    /**
     * 查询试题
     * @param test
     * @return
     */
    public List<Question> SelectQuestionByTest(Test test){
        return questionDao.SelectQuestionByTest(test);
    }
}
